local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.BaseObject())

local PetTool=_G.CommonOHOH.load.PetTool();
local TweenHelper = ClientOHOH.load.TweenHelper();

local instStr={
    CF="ctrl.CF",
    Viewport="ctrl.Viewport",
    BG="ctrl.backimg",
    Title="ctrl.title",
}

function M.new(...)
	return M(...);
end;

function M.ctor(self,ctrl,petId,guid,ui_inst)
    M.super.ctor(self);
    self.ctrl=ctrl
    self.ui=self.ctrl:InitUiInst2(ui_inst,instStr)
    self.petId=petId
    self.petData=PetTool.GetPetDataByPetId(self.petId)
    self.Model=PetTool.GetPetModelByPetId(self.petId)
    self.Model.Parent=self.ui.Viewport
    self.Model:SetPrimaryPartCFrame(self.ui.CF)
    self.AbsoluteSize=self.ui.BG.AbsoluteSize
    self.ui.BG.Rotation=0
    self.gui=guid
    self.ui_inst=ui_inst
    self.ui.Title.TextColor3=ClientOHOH.load.PetCell().GetTitleColor3ById(self.petData.title)
    self.ui.Title.Text=self.petData.titleName
    self.ui.BG.ImageColor3= self.ui.Title.TextColor3
end;

function M.Play(self,time)
    local aniamtionValue= Instance.new("IntValue",self.Model)
    aniamtionValue.Value=0
    aniamtionValue.Changed:Connect(function(value)
        local cf=self.ui.CF*CFrame.Angles(0,math.rad(value),0)
        self.Model:SetPrimaryPartCFrame(cf)
        local s= self.AbsoluteSize*value/360
        self.ui.BG.Size=UDim2.fromOffset(s.X,s.Y)
        -- self.ui.BG.Rotation=value
    end)

    local tw1 = TweenInfo.new(time, Enum.EasingStyle.Quad);
    TweenHelper:PlayTween(aniamtionValue, tw1, {
        Value =360
    });

end

function M.dtor(self)
	M.super.dtor(self);
    self.ui_inst:Destroy()
end;


return M